import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.border.MatteBorder;

/*
 * Created by JFormDesigner on Thu Mar 31 19:42:49 CST 2016
 */

/**
 * @author zhangpinga
 */
public class Netease extends JFrame {
	
	public Netease() {
		initComponents();
	}
	
	public String getDefaultTitle() {
		return "\u7f51\u6613\u56fe\u7247\u4e0b\u8f7d";
	}
	
	public void setTime( String time ) {
		label1.setText( time );
	}
	
	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents
		panel3 = new JPanel();
		label4 = new JLabel();
		panel4 = new JPanel();
		label5 = new JLabel();
		panel7 = new JPanel();
		textField1 = new JTextField();
		panel9 = new JPanel();
		label7 = new JLabel();
		label6 = new JLabel();
		panel10 = new JPanel();
		button1 = new JButton();
		label8 = new JLabel();
		label1 = new JLabel( "00:00" );
		
		// textField1.setText("http://news.163.com/photoview/00AP0001/114744.html#p=BJIDCUEH00AP0001");
		
		// ======== this ========
		setMinimumSize( new Dimension( 600 , 120 ) );
		setTitle( getDefaultTitle() );
		setResizable( false );
		Container contentPane = getContentPane();
		contentPane.setLayout( new BorderLayout() );
		
		// ======== panel3 ========
		{
			panel3.setLayout( new FlowLayout( FlowLayout.LEFT ) );
			
			// ---- label4 ----
			label4.setText( "  " );
			panel3.add( label4 );
		}
		contentPane.add( panel3 , BorderLayout.PAGE_START );
		
		// ======== panel4 ========
		{
			panel4.setBorder( new MatteBorder( 1 , 0 , 0 , 0 , new Color( 214 , 214 , 214 ) ) );
			panel4.setForeground( Color.gray );
			panel4.setToolTipText( "\u72b6\u6001\u680f" );
			panel4.setLayout( new FlowLayout( FlowLayout.LEFT ) );
			
			panel4.add( new JSeparator() );
			panel4.add( label1 );
			label1.setForeground( Color.gray );
			panel4.add( new JSeparator() );
			// ---- label5 ----
			label5.setText( "\u51c6\u5907\u5c31\u7eea" );
			// label5.setForeground(Color.gray);
			panel4.add( label5 );
		}
		contentPane.add( panel4 , BorderLayout.PAGE_END );
		
		// ======== panel7 ========
		{
			panel7.setLayout( new BorderLayout() );
			panel7.add( textField1 , BorderLayout.NORTH );
		}
		contentPane.add( panel7 , BorderLayout.CENTER );
		
		// ======== panel9 ========
		{
			panel9.setLayout( new BorderLayout() );
			
			// ---- label7 ----
			label7.setText( " \u7f51\u5740:" );
			panel9.add( label7 , BorderLayout.NORTH );
			
			// ---- label6 ----
			label6.setText( "   " );
			panel9.add( label6 , BorderLayout.CENTER );
		}
		contentPane.add( panel9 , BorderLayout.LINE_START );
		
		// ======== panel10 ========
		{
			panel10.setLayout( new BorderLayout() );
			
			// ---- button1 ----
			button1.setText( "\u6293\u53d6" );
			button1.addMouseListener( new MouseAdapter() {
				@Override
				public void mouseClicked( MouseEvent e ) {
					button1MouseClicked( e );
				}
			} );
			panel10.add( button1 , BorderLayout.NORTH );
			
			// ---- label8 ----
			label8.setText( "      " );
			panel10.add( label8 , BorderLayout.CENTER );
		}
		contentPane.add( panel10 , BorderLayout.LINE_END );
		pack();
		setLocationRelativeTo( getOwner() );
		// JFormDesigner - End of component initialization
		// //GEN-END:initComponents
	}
	
	private void button1MouseClicked( MouseEvent e ) {
		// /System.out.println("button1MouseClicked");
		lock();
		String url = textField1.getText();
		if ( App.doing( Util.getGoodUrl( url.trim() ) ) ) { return; }
		if ( url != null && url.trim().length() > 0 ) {
			App.mark( Util.getGoodUrl( url.trim() ) );
			new Catch().get( Util.getGoodUrl( url.trim() ) );
		} else {
			release();
		}
	}
	
	public void showMsg( String str ) {
		label5.setText( str );
	}
	
	public void release() {
		button1.setEnabled( true );
		textField1.setEnabled( true );
	}
	
	public void lock() {
		button1.setEnabled( false );
		textField1.setEnabled( false );
	}
	
	// JFormDesigner - Variables declaration - DO NOT MODIFY
	// //GEN-BEGIN:variables
	private JPanel panel3;
	private JLabel label4;
	private JPanel panel4;
	private JLabel label5;
	private JPanel panel7;
	private JTextField textField1;
	private JPanel panel9;
	private JLabel label7;
	private JLabel label6;
	private JPanel panel10;
	private JButton button1;
	private JLabel label8;
	private JLabel label1;
	
	// JFormDesigner - End of variables declaration //GEN-END:variables
	public void setUrl( String string ) {
		textField1.setText( string );
	}
	
}
